﻿<navigation:Page x:Class="$safeprojectname$.ItemListView" 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
        xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
        xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
        xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit" 
        xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
        mc:Ignorable="d"
        d:DesignWidth="500" d:DesignHeight="400"
        Title="Items"
        DataContext="{Binding Source={StaticResource Locator}, Path=ItemListViewModel}" 
        >
        <!-- Set the DataContext to the Locator static resource, specifying the ViewModel name for the Path -->
    
    <!-- Button Style -->
    <navigation:Page.Resources>
        <Style TargetType="Button">
            <Style.Setters>
                <Setter Property="Height" Value="23"/>
                <Setter Property="Width" Value="60"/>
                <Setter Property="Margin" Value="5,0,0,0"/>
            </Style.Setters>
        </Style>
    </navigation:Page.Resources>

    <StackPanel x:Name="LayoutRoot">
        <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
            <!-- Call OrderProduct and bind IsEnabled to CanOrder -->
            <Button Name="loadButton" 
                    Content="Load"
                    IsEnabled="{Binding CanLoad}">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <ei:CallMethodAction 
                            TargetObject="{Binding}"
                            MethodName="LoadItems"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </Button>
            <Button Name="addButton"
                    Content="Add"
                    IsEnabled="{Binding CanAdd}" Click="addItemButton_Click" />
            <Button Name="editButton"
                    Content="Edit" 
                    IsEnabled="{Binding CanEdit}" Click="editItemButton_Click" />
            <Button Name="removeButton"
                    Content="Remove" 
                    IsEnabled="{Binding CanRemove}" Click="removeItemButton_Click" />
            <!-- TODO: Set IsEnabled to True -->
            <Button Name="saveChangesButton"
                    Content="Save Changes" 
                    IsEnabled="False" Width="94">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <ei:CallMethodAction 
                            TargetObject="{Binding}"
                            MethodName="SaveChanges"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </Button>
            <!-- TODO: Set IsEnabled to True -->
            <Button Name="rejectChangesButton"
                    Content="Reject Changes" 
                    IsEnabled="False" Width="94">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <ei:CallMethodAction 
                            TargetObject="{Binding}"
                            MethodName="RejectChanges"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </Button>
        </StackPanel>
        <!-- Bind ItemsSource to Items -->
        <!-- Bind SelectedItem to SelectedItem -->
        <sdk:DataGrid Name="itemsDataGrid"
                      AutoGenerateColumns="False" ItemsSource="{Binding Items}"
                      SelectedItem="{Binding SelectedItem, Mode=TwoWay}" SelectionChanged="itemsDataGrid_SelectionChanged" IsReadOnly="True">
            <!-- Set Binding for each column to property on Item -->
            <sdk:DataGrid.Columns>
                <sdk:DataGridTextColumn Binding="{Binding Path=Id}" CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="Auto" Header="Id" />
                <sdk:DataGridTextColumn Binding="{Binding Path=Name}" CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="Auto" Header="Name" />
            </sdk:DataGrid.Columns>
        </sdk:DataGrid>
        <Grid>
            <!-- Bind IsBusy to IsBusy -->
            <toolkit:BusyIndicator Name="isBusyIndicator" Height="80" Width="200" 
                IsBusy="{Binding IsBusy}" Margin="152,39,148,-39" />
        </Grid>
    </StackPanel>
    
</navigation:Page>
